import request from '../request'
import type {
  DeleteGroupMemberResponseData,
  GetGroupsResponseData,
  UpdateGroup,
  UpdateGroupResponseData
} from './type'

enum API {
  GETGROUPS_URL = '/group', // 获取群列表
  UPLOAD_URL = '/group/upload', // 群头像上传接口
  UPDATEGROUP_URL = '/group', // 更新群信息
  DELETEGROUPMEMBER_URL = '/group/member' // 删除群成员
}

// 获取群列表接口
export const reqGetGroups = (
  params?: Partial<{
    pageNum: number
    pageSize: number
    keyword: string
  }>
) =>
  request<GetGroupsResponseData, any>({
    url: API.GETGROUPS_URL,
    method: 'get',
    params
  })

// 群头像上传接口
export const uploadAvatarUrl =
  `${import.meta.env.VITE_APP_API_URL}:${import.meta.env.VITE_APP_API_PORT}` +
  import.meta.env.VITE_APP_PATH +
  API.UPLOAD_URL

// 更新群信息
export const reqUpdateGroup = (data: UpdateGroup) =>
  request<UpdateGroupResponseData, any>({
    url: API.UPDATEGROUP_URL,
    method: 'patch',
    data
  })

// 删除群成员接口
export const reqDeleteGroupMember = (params: {
  userId: string
  groupId: string
}) =>
  request<DeleteGroupMemberResponseData, any>({
    url: API.DELETEGROUPMEMBER_URL,
    method: 'delete',
    params
  })
